package com.sqlcheck.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import lombok.Data;

/**
 * 环境特定配置类
 * 根据不同环境（dev, sit, prd, odev, oprd）提供特定配置
 */
@Configuration
@ConfigurationProperties(prefix = "environment")
@Data
public class EnvironmentConfig {
    
    private String name;
    private String description;
    private Database database = new Database();
    private Monitoring monitoring = new Monitoring();
    private Performance performance = new Performance();
    
    @Data
    public static class Database {
        private String host;
        private int port;
        private String schema;
        private Pool pool = new Pool();
        private boolean ssl = false;
        
        @Data
        public static class Pool {
            private int maxSize = 20;
            private int minIdle = 5;
            private long connectionTimeout = 30000;
            private long idleTimeout = 600000;
            private long maxLifetime = 1800000;
        }
    }
    
    @Data
    public static class Monitoring {
        private boolean healthDetails = false;
        private String[] exposedEndpoints = {"health", "info"};
        private Logging logging = new Logging();
        
        @Data
        public static class Logging {
            private String level = "INFO";
            private String sqlLevel = "WARN";
            private String webLevel = "INFO";
            private String file = "logs/sqlcheck-backend.log";
            private String maxSize = "10MB";
            private int maxHistory = 30;
        }
    }
    
    @Data
    public static class Performance {
        private int maxConcurrentTasks = 5;
        private int threadPoolSize = 10;
        private long cacheExpireMinutes = 30;
        private long sessionTimeoutMinutes = 30;
    }
    
    /**
     * 判断是否为开发环境
     */
    public boolean isDevelopment() {
        return "dev".equals(name) || "odev".equals(name);
    }
    
    /**
     * 判断是否为生产环境
     */
    public boolean isProduction() {
        return "prd".equals(name) || "oprd".equals(name);
    }
    
    /**
     * 判断是否为测试环境
     */
    public boolean isTesting() {
        return "sit".equals(name) || "test".equals(name);
    }
}